package com.asiainfo.application;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.asiainfo.dao.OperatorData;
import com.asiainfo.service.AddMemberInfo;
import com.asiainfo.validator.ValidatorCard;
import com.asiainfo.validator.ValidatorMember;

public class RunService {
	public static void main(String[] args) throws IOException{
		System.out.println("请输入要执行的操作");
		
		while(true){
			
			//获取输入的信息，并转换为数组
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] params = br.readLine().split(" ");
			int memberId = -1;
			String cardType = null;
			int cardTimes = -1;

			//根据输入的信息判断需要调用的函数，执行对应的方法
			if (params[0].equals("iyoga") && params[1].equals("add-member")){
				String memberName = params[2];
				String memberAddr = params[3];
				String memberWork = params[4];
				if (ValidatorMember.validateMember(memberName, memberAddr, memberWork)) {
					memberId = AddMemberInfo.addMember(memberName, memberAddr, memberWork);
				}
				if (memberId != 0){
					System.out.println("OK. " + memberName + "'s id is " + memberId+".");
				}
			}
			
			//根据设置的卡类型设置响应的卡对象属性
			else if (params[0].equals("iyoga") && params[1].equals("add-card")){
				String memberName = params[2];
				memberId = OperatorData.getMemIdByName(memberName);
				if (params[3].equals("年卡")){
					cardType = "Y";
					
				}else if (params[3].equals("次卡")){
					cardType = "T";
					cardTimes = Integer.parseInt(params[4]);
				}
				System.out.println(cardType);
				if (ValidatorCard.validaterCard(memberId, cardType,cardTimes)) {
					int cardId = AddMemberInfo.addCard(memberId, cardType, cardTimes);
					System.out.println("OK. " + memberName + "'s Card id is " + cardId + ".");
				}
			}else {
				System.out.println("输入信息有误，请重新输入。");
				continue;
			}
		}
	}
}
